from tortoise import fields
from datetime import datetime
from .base import BaseModel, TimestampMixin


class SysLogininfor(BaseModel, TimestampMixin):
    """系统访问记录"""

    info_id = fields.IntField(pk=True, description="访问ID")

    user_name = fields.CharField(max_length=50, null=True, description="用户账号")

    ipaddr = fields.CharField(max_length=128, null=True, description="登录IP地址")

    login_location = fields.CharField(max_length=255, null=True, description="登录地点")

    browser = fields.CharField(max_length=50, null=True, description="浏览器类型")

    os = fields.CharField(max_length=50, null=True, description="操作系统")

    login_status = fields.CharField(max_length=1, null=True, description="登录状态（0成功 1失败）")

    status = fields.CharField(max_length=1, null=True, description="状态（0正常 2删除）")

    msg = fields.CharField(max_length=255, null=True, description="提示消息")

    login_time = fields.DatetimeField(null=True, description="访问时间")

    create_by = fields.CharField(max_length=64, null=True, description="创建者")

    create_time = fields.DatetimeField(null=True, description="创建时间")

    update_by = fields.CharField(max_length=64, null=True, description="更新者")

    update_time = fields.DatetimeField(null=True, description="更新时间")

    class Meta:
        table = "sys_logininfor"

    def __str__(self):
        return f"{self.info_id}"